package ihm;


import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import metier.Plat;
import metier.Serveur;
import metier.Table;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import java.awt.Font;

public class Menu extends JFrame implements ActionListener 
{

	private JPanel contentPane;
	private JMenuBar menuBar;
	private JMenu mnFichier;
	private JMenu mnNouveau;
	private JMenuItem mntmCommande;
	private JMenuItem mntmQuitter;
	private JMenu mnDonneesMetiers;
	private JMenu mnServeur;
	private JMenuItem mntmAjouterServ;
	private JMenuItem mntmModifSupServ;
	private JMenu mnTable;
	private JMenuItem mntmAjouterTab;
	private JMenuItem mntmModifSupTab;
	private JMenu mnPlat;
	private JMenuItem mntmAjouterPlat;
	private JMenuItem mntmModifSupPlat;
	
	private Vector <Serveur> lesServeurs;
	private Vector <Table> lesTables;
	private Vector <Plat> lesPlats;
	private JLabel lblNewLabel;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) 
	{
		EventQueue.invokeLater(new Runnable() 
		{
			public void run() 
			{
				try 
				{
					Menu frame = new Menu();
					frame.setVisible(true);
				} 
				catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Menu() 
	{
		setTitle("Menu principal");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 650, 445);
		
		menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		mnFichier = new JMenu("Fichier");
		menuBar.add(mnFichier);
		
		mnNouveau = new JMenu("Nouveau");
		mnFichier.add(mnNouveau);
		
		mntmCommande = new JMenuItem("Commande");
		mnNouveau.add(mntmCommande);
		mntmCommande.addActionListener(this);
		
		mntmQuitter = new JMenuItem("Quitter");
		mnFichier.add(mntmQuitter);
		
		mnDonneesMetiers = new JMenu("Donn\u00E9es Metiers");
		menuBar.add(mnDonneesMetiers);
		
		mnServeur = new JMenu("Serveur");
		mnDonneesMetiers.add(mnServeur);
		
		mntmAjouterServ = new JMenuItem("Ajouter");
		mnServeur.add(mntmAjouterServ);
		mntmAjouterServ.addActionListener(this);
		
		mntmModifSupServ = new JMenuItem("Modifier/Supprimer");
		mnServeur.add(mntmModifSupServ);
		mntmModifSupServ.addActionListener(this);
		
		mnTable = new JMenu("Table");
		mnDonneesMetiers.add(mnTable);
		
		mntmAjouterTab = new JMenuItem("Ajouter");
		mnTable.add(mntmAjouterTab);
		mntmAjouterTab.addActionListener(this);
		
		mntmModifSupTab = new JMenuItem("Modifier/Supprimer");
		mnTable.add(mntmModifSupTab);
		mntmModifSupTab.addActionListener(this);
		
		mnPlat = new JMenu("Plat");
		mnDonneesMetiers.add(mnPlat);
		
		mntmAjouterPlat = new JMenuItem("Ajouter");
		mnPlat.add(mntmAjouterPlat);
		mntmAjouterPlat.addActionListener(this);
		
		mntmModifSupPlat = new JMenuItem("Modifier/Supprimer");
		mnPlat.add(mntmModifSupPlat);
		mntmModifSupPlat.addActionListener(this);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JLabel lblBienvenue = new JLabel("Bienvenue ");
		lblBienvenue.setFont(new Font("Segoe Script", Font.PLAIN, 44));
		lblBienvenue.setHorizontalAlignment(SwingConstants.CENTER);
		lblBienvenue.setBounds(118, 29, 387, 37);
		panel.add(lblBienvenue);
		
		lblNewLabel = new JLabel("");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setIcon(new ImageIcon(Menu.class.getResource("/images/resto.png")));
		lblNewLabel.setBounds(141, 114, 332, 214);
		panel.add(lblNewLabel);
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		contentPane.removeAll();
        JInternalFrame f = null;
       
        
		if (e.getSource() == mntmCommande)
		{	 
			f = new PasserCommande(lesServeurs, lesTables, lesPlats);	
		}
		if (e.getSource() == mntmAjouterServ)
		{
			f = new AjoutServeur();	
		}
		if (e.getSource() == mntmAjouterTab)
		{
			f = new AjoutTable();	
		}
		if (e.getSource() == mntmAjouterPlat)
		{
			f = new AjoutPlat();	
		}
		if (e.getSource() == mntmModifSupServ)
		{
			f = new ModifSupServeur(lesServeurs);
		}
		if (e.getSource() == mntmModifSupTab)
		{
			f = new ModifSupTable(lesTables);
		}
		if (e.getSource() == mntmModifSupPlat)
		{
			f = new ModifSupPlat(lesPlats);
		}
		contentPane.add(f);
        f.setVisible(true);
		
	}
}
